package net.bwie.realtime.jtp.Rpfunction;

import net.bwie.realtime.jtp.bean.Order;
import org.apache.flink.api.common.functions.AggregateFunction;
import org.apache.flink.api.java.tuple.Tuple3;

/**
 * 简介说明:
 *
 * @author: LiLi
 * @date: 2025/05/28 10:56:41
 * @version: 1.0
 */
public class PromotionAggregation implements AggregateFunction<Order, Tuple3<String, Double, Long>, Tuple3<String, Double, Long>> {
    @Override
    public Tuple3<String, Double, Long> createAccumulator() {
        return Tuple3.of("", 0.0, 0L);
    }

    @Override
    public Tuple3<String, Double, Long> add(Order value, Tuple3<String, Double, Long> accumulator) {
        return Tuple3.of(
                value.getPromotionId(),
                accumulator.f1 + value.getPayment(),
                accumulator.f2 + 1
        );
    }

    @Override
    public Tuple3<String, Double, Long> getResult(Tuple3<String, Double, Long> accumulator) {
        return accumulator;
    }

    @Override
    public Tuple3<String, Double, Long> merge(Tuple3<String, Double, Long> a, Tuple3<String, Double, Long> b) {
        return Tuple3.of(a.f0, a.f1 + b.f1, a.f2 + b.f2);
    }
}
